package com.gjt.URI_URL;

import java.io.*;
import java.net.URL;

/**
 * Created with Intel IDEA.
 * 使用bing 完成搜素
 *
 * @Auther: gjt
 * @Date: 2024/3/23 14:09
 */
public class Search {
    public static void main(String[] args) {
        String target = "";
        for (String arg : args) {
            target +=arg + " ";
        }
        target = target.trim();

        QueryString query = new QueryString();
        query.add("q",target);

        try{
            URL url = new URL("https://cn.bing.com/search?" + query);
            try(InputStream in = new BufferedInputStream(url.openStream())){
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                int c;
                char[] buf = new char[1024];
                while((c = reader.read(buf)) != -1){
                    System.out.println(new String(buf));
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
